package com.dys.controller;

import com.dys.service.CustomerService;
import com.dys.util.Customer;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @RequestMapping("/customerReg")
    public ModelAndView customerReg(Customer customer) {
        boolean flag = customerService.customerReg(customer);
        ModelAndView mv = new ModelAndView("/index");
        String ss;
        if(flag) {
            ss="恭喜你注册成功";
        } else  ss = "注册失败";
        mv.addObject("ss",ss);
        return mv;
    }

    @ResponseBody
    @RequestMapping("/checkName")
    public String checkName(@Param("name") String name) {
        String cname = customerService.checkName(name);
        if(cname != null) return "true";
        else return "false";

    }
}
